import request from '@/utils/request'

const api_name = '/admin/system/sysRole'

// 分页查询角色数据
export const GetSysRoleListByPage = (pageNum, pageSize, roleName) => {
    return request({
        url: `${api_name}/findByPage/${pageNum}/${pageSize}?roleName=${roleName}`,
        method: 'post',
        //接口有@RequestBody注解 前端 data : 名称,以json格式传输
        //接口没有@RequestBody注解 , 前端params : 名称[非json的普通参数]
    })
}

// 添加角色请求方法
//?name=${sysRole.name}&description=${sysRole.description}
export const SaveSysRole = sysRole => {
    return request({
        url: `${api_name}/saveSysRole`,
        method: 'post',
        data: sysRole
    })
}

// 保存修改
export const UpdateSysRole = data => {
    return request({
        url: `${api_name}/updateSysRole`,
        method: 'put',
        data: data
    })
}

// 删除角色
export const DeleteSysRoleById = roleId => {
    return request({
        url: `${api_name}/deleteById/${roleId}`,
        method: 'delete',
    })
}


// 查询所有的角色数据
export const GetAllRoleList = userId => {
    return request({
        url: '/admin/system/sysRole/findAllRoles/' + userId,
        method: 'get',
    })
}

// 查询指定角色所对应的菜单id
export const GetSysRoleMenuIds = roleId => {
    return request({
        url: '/admin/system/sysRoleMenu/findSysRoleMenuByRoleId/' + roleId,
        method: 'get',
    })
}

// 根据角色分配菜单请求方法
export const DoAssignMenuIdToSysRole = assignMenuDto => {
    return request({
        url: '/admin/system/sysRoleMenu/doAssign',
        method: 'post',
        data: assignMenuDto,
    })
}
